#!/usr/bin/env python
import sys 

from os.path import join
from site import addsitedir

from django.conf import settings
from django.core.management import setup_environ, execute_from_command_line
from django.core.management import execute_manager

try:
    import settings as settings_mod # Assumed to be in the same directory.
except ImportError:
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
    sys.exit(1)

# setup the environment before we start accessing things in the settings.
setup_environ(settings_mod)

path = addsitedir(join(settings.PROJECT_ROOT, "libs/external_libs"), set())
if path:
    sys.path = list(path) + sys.path
sys.path.insert(0, join(settings.PROJECT_ROOT, "external_apps"))

from django.db.models import signals

try:
    from notification import models as notification
    
    def create_notice_types(app, created_models, verbosity, **kwargs):
        notification.create_notice_type("project_created", "Project Created", "A project has been created")
        
        notification.create_notice_type("aim_created", "Aim Created", "An aim has been created")
        
        notification.create_notice_type("deliverable_complete", "Deliverable Complete", "A deliverable has been completed")
        notification.create_notice_type("deliverable_incomplete", "Deliverable Incomplete", "A deliverable has been marked as incomplete")
        notification.create_notice_type("deliverable_created", "Deliverable Created", "A Deliverable has been created")
        notification.create_notice_type("deliverable_updated", "Deliverable Updated", "A Deliverable has been udpated")
        notification.create_notice_type("request_deliverable_update", "Request Deliverable Update", "Request an update from the lead on a deliverable.")

        notification.create_notice_type("project_created", "Project Created", "A project has been created")

        notification.create_notice_type("request_task_update", "Request Task Update", "Request an update from the lead on a task.")
        notification.create_notice_type("task_complete", "Task Complete", "A task has been completed")
        notification.create_notice_type("task_incomplete", "Task Incomplete", "A task has been marked as incomplete")
        notification.create_notice_type("task_created", "Task Created", "A task has been created")
        notification.create_notice_type("task_updated", "Task Updated", "A task has been updated")
    
    signals.post_syncdb.connect(create_notice_types, sender=notification)
except ImportError:
    print "Skipping creation of NoticeTypes as notification app not found"

if __name__ == "__main__":
    execute_from_command_line()
